From 8faa27a736710018ad6325609b2a9f48dc4e01d6 Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Wed, 8 Dec 2004 14:53:21 +0000 Subject: [PATCH] Fixed two segfaults involving stack filter: empty lists didn't push right, and we didn't udpate the waypt_count on stack operations. --- gpsbabel/defs.h | 1 + gpsbabel/queue.h | 13 +++++++++---- gpsbabel/stackfilter.c | 9 +++++++++ gpsbabel/waypt.c | 6 ++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 5f008e1ec..e0ac7e40c 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -266,6 +266,7 @@ void waypt_compute_bounds(bounds *); void waypt_flush(queue *); void waypt_flush_all(void); unsigned int waypt_count(void); +void set_waypt_count(unsigned int nc); void free_gpx_extras (xml_tag * tag); void xcsv_setup_internal_style(const char *style_buf); void xcsv_read_internal_style(const char *style_buf); diff --git a/gpsbabel/queue.h b/gpsbabel/queue.h index 2cbb72748..e042e235e 100644 --- a/gpsbabel/queue.h +++ b/gpsbabel/queue.h @@ -33,10 +33,15 @@ queue * dequeue(queue *element); #define QUEUE_LAST(head) (head)->prev #define QUEUE_EMPTY (head)->next == head #define QUEUE_MOVE(newhead,oldhead) \ - (newhead)->next = (oldhead)->next; \ - (newhead)->prev = (oldhead)->prev; \ - (newhead)->next->prev = (newhead); \ - (newhead)->prev->next = (newhead); \ + if ( (oldhead)->next == (oldhead) ) {\ + (newhead)->next = (newhead)->prev = (newhead); \ + } \ + else { \ + (newhead)->next = (oldhead)->next; \ + (newhead)->prev = (oldhead)->prev; \ + (newhead)->next->prev = (newhead); \ + (newhead)->prev->next = (newhead); \ + } \ (oldhead)->next = (oldhead)->prev = (oldhead) #define ENQUEUE_TAIL(listhead, element) \ diff --git a/gpsbabel/stackfilter.c b/gpsbabel/stackfilter.c index adb3a9144..c8c5021fb 100644 --- a/gpsbabel/stackfilter.c +++ b/gpsbabel/stackfilter.c @@ -62,6 +62,7 @@ arglist_t stackfilt_args[] = { struct stack_elt { queue waypts; + unsigned int waypt_ct; struct stack_elt *next; } *stack = NULL; @@ -74,10 +75,13 @@ stackfilt_process(void) queue *tmp = NULL; queue tmp_queue; waypoint *wpt_tmp; + unsigned int tmp_count; if ( opt_push ) { tmp_elt = (struct stack_elt *)xmalloc(sizeof(struct stack_elt)); QUEUE_MOVE(&(tmp_elt->waypts), &waypt_head); + tmp_elt->waypt_ct = waypt_count(); + set_waypt_count(0); tmp_elt->next = stack; stack = tmp_elt; if ( opt_copy ) { @@ -102,6 +106,7 @@ stackfilt_process(void) else { waypt_flush( &waypt_head ); QUEUE_MOVE(&(waypt_head), &(stack->waypts) ); + set_waypt_count(stack->waypt_ct); } stack = tmp_elt->next; xfree( tmp_elt ); @@ -118,6 +123,10 @@ stackfilt_process(void) QUEUE_MOVE(&tmp_queue, &(tmp_elt->waypts) ); QUEUE_MOVE(&(tmp_elt->waypts), &waypt_head ); QUEUE_MOVE(&waypt_head, &tmp_queue ); + + tmp_count = waypt_count(); + set_waypt_count( tmp_elt->waypt_ct ); + tmp_elt->waypt_ct = tmp_count; } } diff --git a/gpsbabel/waypt.c b/gpsbabel/waypt.c index fde54f87b..ae15046f4 100644 --- a/gpsbabel/waypt.c +++ b/gpsbabel/waypt.c @@ -135,6 +135,12 @@ waypt_count(void) return waypt_ct; } +void +set_waypt_count(unsigned int nc) +{ + waypt_ct = nc; +} + void waypt_disp(const waypoint *wpt) { -- 2.30.2